<?php

$userid             	= get_loggedin_userid();
$name               	= get_input('name');
$description		= get_input('description');
$category_id        	= get_input('category_id');
$location_descriptive	= get_input('location_descriptive');
$geographic_level   	= get_input('geographic_level');
$lat                	= get_input('lat');
$lng                	= get_input('lng');
$image_url          	= get_input('image_url');
$rating             	= get_input('rating');
$source                 = intval(get_input('source'));
$id_str                 = get_input('id_str');

$interest_id = add_interest($userid, $category_id, $name, $description, $geographic_level, $source, $id_str);

if($interest_id) {
    // add location
    add_interest_location($interest_id, $lat, $lng, $location_descriptive);
    // add photo
    add_photo($interest_id, $image_url);
    // add rating
    if($rating != 999) {
        $rating_id = add_interest_rating($interest_id, $userid, $rating);
        // add opinions stream (activities)
        add_opinions_stream($userid, $userid, $rating_id, '2', 'no', '');
    }
}

if($interest_id)
    echo json_encode(export_result(200, array($interest_id)));
else
    echo json_encode(export_result(400, array('Error')));

?>